clear all;
close all;
full_quality_img = imread('chinese_gardens.JPG');

max_size = 600;
[height , width, depth] = size(full_quality_img);
if height > width %%  high pic
    show_scale = max_size/height;
else %% wide pic
    show_scale = max_size/width;
end

bench_img = imresize(full_quality_img, show_scale);
[height , width, depth] = size(bench_img);

imwrite(bench_img,'base.jpg');
figure;imshow(bench_img);

% create rotation
% rotation_folder = 'rotation';
% mkdir(rotation_folder);
% 
% for deg = 1:360
%     output = imrotate(bench_img,deg);
%     figure; imshow(output./255);
%     imwrite(uint8(output),[rotation_folder  '/' num2str(deg) '.jpg']);
% end


%scaling
% scaling_folder = 'scaling_bonus';
% mkdir(scaling_folder);
% for scale = 9:10
%     real_scale = show_scale*scale;
%     output = imresize(full_quality_img, real_scale);
%     imwrite(uint8(output),[scaling_folder  '/' num2str(scale) '.jpg']);
%     
%     real_scale = show_scale/scale;
%     output = imresize(full_quality_img, real_scale);
%     imwrite(uint8(output),[scaling_folder  '/1_by_' num2str(scale) '.jpg']);
%     
% end

%illumination
% illumination_folder = 'illumination';
% mkdir(illumination_folder);
% for illu = 5:10:255
%     plus_img = min(bench_img + illu,255);
%     minus_img = max(bench_img - illu,0);
%     
%     imwrite(uint8(plus_img),[illumination_folder  '/plus' num2str(illu) '.jpg']);
%     imwrite(uint8(minus_img),[illumination_folder  '/minus' num2str(illu) '.jpg']);
% end


% %gaussian noise
%  gaussian_folder = 'gaussian_noise';
% mkdir(gaussian_folder);
% for variance = 0.005:0.005:0.04
%    blurred_img = imnoise(bench_img,'gaussian',0,variance);
%    imwrite(uint8(blurred_img),[gaussian_folder  '/variance_' num2str(variance) '.jpg']);
% end

% salt&pepper noise
%  snp_folder = 'snp_noise';
% mkdir(snp_folder);
% for density = 0.05:0.05:1
%    blurred_img = imnoise(bench_img,'salt & pepper',density);
%    imwrite(uint8(blurred_img),[snp_folder  '/density_' num2str(density) '.jpg']);
% end

%gaussian blur
 gaussian_folder = 'gaussian_blur_bonus';
mkdir(gaussian_folder);
for kernel_size = 31:2:61
    sigma = kernel_size/5;
    G = fspecial('gaussian',[kernel_size kernel_size],sigma);
    blurred_img = imfilter(bench_img,G,'same');
   imwrite(uint8(blurred_img),[gaussian_folder  '/kernel_size_' num2str(kernel_size) '_sigma_'  num2str(sigma)  '.jpg']);
end

%perspective
% perspective_folder = 'perspective';
% mkdir(perspective_folder);
% 
% corners= [ 0 0;
%            0 height;
%            width 0;
%            width height];
% for scale = 0.9:-0.1:0.1
%     outer_x = width*scale;
%     outer_y = height*scale;
%     tform = maketform('projective',corners, [0 0; 0 height;outer_x 0 ; outer_x outer_y]);
%     output = imtransform(bench_img,tform);
%     imwrite(uint8(output),[perspective_folder  '/scale' num2str(scale)  '.jpg']);
% end
